main(n,r,s)
{
	char c[21];
	for(gets(c);gets(c);printf("%d\n",r))
		for(n=r=0,s=strlen(c);s;)
			r+=(c[n++]&1)<<--s;
}
